package chapter06

object Demo17_Extend {
  def main(args: Array[String]): Unit = {
    //类型的检车和转换
    val student: Student17 = new Student17("alice" ,99)
    student.study()
    student.sayHi()
    val person17: Person17 = new Student17("bob" , 88)
    person17.sayHi()  //Hi from student bob

    //类型判断
    println("student is Student17: " + student.isInstanceOf[Student17])
    println("student is person17: " + student.isInstanceOf[Person17])
    println("student is person17: " + person17.isInstanceOf[Person17])
    println("person is Student17: " + person17.isInstanceOf[Student17])

    val person2: Person17 = new Person17("casy" , 22)
    println("person2 is Student17 : " + person2.isInstanceOf[Student17])  //false  父类对象不能改变子类的类型

    //类型转换
    if (person17.isInstanceOf[Student17]){
      val newStudent = person17.asInstanceOf[Student17]
      newStudent.study()
    }
    println(classOf[Student17])

    //测试枚举类
    println(WorkDay.MONDAY)

  }
}
class Person17(val name: String , val age: Int){
  def sayHi(): Unit = println("hi from person " + name)
}
class Student17(name: String , age: Int) extends Person17(name , age ){
  override def sayHi(): Unit = println("Hi from student " + name)
  def study(): Unit = {
    println("student study")
  }
}

//枚举类对象
object WorkDay extends Enumeration{
  val MONDAY = Value(1 , "Monday")
  val TUESDAY = Value(2, "Tuesday")
}

//定义应用类
object TestAPP extends App{
  println("app start")
}